package com.zsh.sample.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * Copyright (C), 2020-2020
 * Author: Zhoushaohua
 * Date: 2020/4/4 21:55
 * Description: 注解解释器
 */
public class AnnotationPareser {

    public static void pareser(String clazzName) {
        try {
            Class clazz = Class.forName(clazzName);
            if (!clazz.isAnnotationPresent(Description.class)) {
                System.out.println("isAnnotationPresent is false!");
                return;
            }

            Description description = (Description) clazz.getAnnotation(Description.class);
            System.out.println(description.value());

            Method[] mothods = clazz.getMethods();
            for (Method method : mothods) {
                if (method.isAnnotationPresent(Description.class)) {
                    System.out.println(method.getAnnotation(Description.class).value());
                }
            }

            for (Method method : mothods) {
                Annotation[] annotations = method.getAnnotations();
                for (Annotation annotation : annotations) {
                    if(annotation instanceof Description){
                        System.out.print(((Description) annotation).value());
                    }
                }
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
